package com.zzxx.mapper;

import com.zzxx.domain.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface UserInfoMapper {

    @Select("select * from users")
    List<UserInfo> findAll();

    @Results(id = "userInfoMap", value = {
            @Result(column = "id", property = "id"),
            @Result(column = "username", property = "username"),
            @Result(column = "email", property = "email"),
            @Result(column = "password", property = "password"),
            @Result(column = "phoneNum", property = "phoneNum"),
            @Result(column = "status", property = "status"),
            @Result(column = "id", property = "roles",
                    many = @Many(select = "com.zzxx.mapper.RoleMapper.findByUid"))})
    @Select("select * from users where username=#{username}")
    UserInfo findByUsername(String username);

    @Select("select * from users where id = #{id}")
    @ResultMap("userInfoMap")
    UserInfo findByUid(String uid);

    @Insert("insert into users(id,username,password,email,phoneNum,status) values(#{id}, #{username}, #{password},#{email},#{phoneNum},#{status})")
    void insert(UserInfo userInfo);

}
